package com.example.aopdemo.aspect;

/*
 * @author zzr
 * @date: 2025/10/02  19:29
 * @description:
 */

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
//@Component
public class TimeAspect {
    @Around("execution(* com.example.aopdemo.controller.*.*(..))")
    public Object readTime(ProceedingJoinPoint pjp) throws Throwable {

        long beginTime = System.currentTimeMillis();
        log.info("Around 开始执行");
        Object proceed = pjp.proceed();
        log.info("Around 结束执行");
        long endTime = System.currentTimeMillis();
        if (log.isInfoEnabled()) {
            log.info("耗时为：" + (endTime - beginTime) + "ms");
        }
        return proceed;
    }
}
